<!DOCTYPE html>
<html>

	<head>
		<meta name="viewport" content="width=device-width, minimum-scale=1, maximum-scale=1">
		<meta charset="UTF-8">
		<title></title>
		<link rel="stylesheet" href="../../css/iuapmobile.um.css">
		<link rel="stylesheet" href="../../css/font-icons.css">
		<link rel="stylesheet" href="../../css/iscroll.css" />
		<link rel="stylesheet" type="text/css" href="../../css/iuapmobile.um.listview.css">
		<link rel="stylesheet" type="text/css" href="../../css/iuapmobile.um.listview.css">

		<style>
			.msg-info {
				position: relative;
			}
			
			.msg-info .um-badge {
				position: absolute;
				right: -10px;
				font-size: 12px;
			}
			
			.msg-header {
				width: 40px;
				height: 40px;
				line-height: 40px;
				background: blue;
				border-radius: 50%;
				text-align: center;
				color: white;
			}
			
			#selectcangku_dummy {
				border: none;
				padding-left: 10px;
				color: #555;
				font-size: 14px;
				text-align: right;
				margin-right: 20px;
				width: 100%;
			}
			
			#selectcangku_dummy:disabled {
				background: #fff;
			}
			
		</style>

		<script type="text/javascript" src="../../js/knockout.js"></script>
		<script src="../../js/jquery.min.js"></script>
		<script src="../../js/iscroll.js"></script>
		<script src="../../js/summer.js"></script>
		<script src="../../js/Frameworks/iuapmobile.frameworks.ui.js"></script>
		<script type="text/javascript" src="../../js/Frameworks/iuapmobile.frameworks.listview.js"></script>
		<script src="../../js/angular.min.js"></script>

		<script>
			function $pageReady() {
				/*这里编写与原生服务相关的代码逻辑，例如对原生设备服务的调用，对网络服务的调用等*/
				//toasts("Mobile Native Ready");
			}

			$(function() {

			});
		</script>

	</head>

	<body class="f13" ng-app="myApp" ng-controller="myCtrl">
		<div class="um-page" id="disassemble_indetail">
			<div class="um-header">
				<a class="um-back back">返回</a>
				<h3>拆机入库页面</h3>
			</div>
			<div class="um-content">

				<ul class="um-list">
					<li class="um-list-item">
						<div class="um-list-item-inner">
							<div class="um-list-item-left pl5">
								施工单位：
							</div>
							<div class="um-list-item-right">
								<span>{{builderUnit}}</span>
							</div>
						</div>
					</li>
					<li class="um-list-item">
						<div class="um-list-item-inner">
							<div class="um-list-item-left pl5">
								42寸立式三屏：{{sb01_num}}
							</div>
							<div class="um-list-item-right">
								43寸立式三屏：{{sb02_num}}
							</div>
						</div>
					</li>
					<li class="um-list-item">
						<div class="um-list-item-inner">
							<div class="um-list-item-left pl5">
								50寸立式三屏：{{sb03_num}}
							</div>
							<div class="um-list-item-right">
								49寸挂式单屏：{{sb04_num}}
							</div>
						</div>
					</li>
					<li class="um-list-item">
						<div class="um-list-item-inner">
							<div class="um-list-item-left pl5">
								43寸挂式单屏：{{sb05_num}}
							</div>
							<div class="um-list-item-right">

							</div>
						</div>
					</li>
					<li class="um-list-item">
						<div class="um-list-item-inner">
							<div class="um-list-item-left pl5">
								加长装置数量<span class="um-red">(剩余{{jczz_num}})</span>：
							</div>
							<div class="um-list-item-right">
								<input type="Number" ng-model="isNeedExtendevice" class="form-control mt5 mb5 tr" placeholder="请填写加长装置数量" style="padding-right: 0px;" />
							</div>
						</div>
					</li>
					<li class="um-list-item">
						<div class="um-list-item-inner">
							<div class="um-list-item-left pl5">
								吊装支架数量<span class="um-red">(剩余{{dzzj_num}})</span>：
							</div>
							<div class="um-list-item-right">
								<input type="Number" ng-model="hoistingCount" class="form-control mt5 mb5 tr" placeholder="请填写吊装支架数量" style="padding-right: 0px;" />
							</div>
						</div>
					</li>
					<li class="um-list-item">
						<div class="um-list-item-inner">
							<div class="um-list-item-left pl5">
								选择仓库：
							</div>
							<div class="um-list-item-right">
								<select id='selectcangku' class="select" ng-model="warehouseid">
									<option ng-repeat="x in cangku" value="{{x.pk_doc}}">{{x.doc_name}}</option>
								</select>
							</div>
						</div>
					</li>
				</ul>
				<div class="um-bgc-blue pt10 pb10 f14 um-white">
					<span class="pl10">设备信息列表</span>
					<span class="fr">
						<i class="ti-plus mr10" style="color: #fff;" onclick="RQ()"></i>
					</span>
				</div>

				<div class="um-listview-wrap" id="listview">
					<ul class="um-list um-no-active f12">
						<li class="um-listview-row" ng-repeat="x in devices">
							<a href="#" class="um-list-item um-swipe-action um-no-icon">
								<div class="um-list-item-inner">
									<div class="um-list-item-body um-text-overflow f14" style="padding-right:5px;">
										<div class="um-bgc-gray um-white pt5 pb5">
											︱设备编号:<span>{{x.deviceId}}</span>
											<span class="fr">
												<i class="ti-close mr10"  ng-click="deleteDriver($index)"></i>
											</span>
										</div>
										<div class="um-box w ml15">
											<div class="um-bf1  mt5 mb5">
												品牌
											</div>
											<div class="um-bf2 mt5 mb5">
												<span>{{x.brand}}</span>
											</div>
										</div>
										<div class="um-box w ml15">
											<div class="um-bf1  mt5 mb5">
												物料信息
											</div>
											<div class="um-bf2 mt5 mb5" ng-click="changePage($index)">
												<span>{{x.point.doc_name}}</span>
											</div>
										</div>
									</div>
								</div>
							</a>
						</li>
					</ul>
				</div>
				<a href="#Actualport" id="toActualport" style="display: none;">asd</a>
			</div>
			<div class="um-footer">
				<button class="btns mb10" onclick="Submit();">
					完成
				</button>
			</div>
		</div>

		<div class="um-page" id="Actualport">
			<div class="um-header">
				<a href="#Actual" class="um-back toActual">返回</a>
				<h3>物料选择</h3>
			</div>
			<div class="um-content">
				<ul class="um-list um-no-active">
					<li class="um-listview-row" ng-repeat="x in pointData">
						<a href="#" class="um-list-item um-swipe-action um-no-icon" ng-click="changePort($index)">
							<div class="um-list-item-inner">
								<div class="um-list-item-body um-text-overflow f14" style="padding-right:5px;">
									<div class="um-bgc-blue um-white pt5 pb5 ">
										︱物料编码:<span>{{x.doc_code}}</span>
									</div>
									<div class="w">
										<div class="um-md-6 w_50 fl mt10 mb10">
											物料名称:<span>{{x.doc_name}}</span>
										</div>
										<!--<div class="um-md-6 w_50 fl mt10 mb10">
											<span>.</span>
										</div>-->
									</div>
								</div>
							</div>
						</a>
					</li>
				</ul>
			</div>
		</div>
		<script>
			var angularScope; //angla对象
			var pageParam; //页面数据
			$(function() {
				// var curr = new Date().getFullYear();
				var opt = {
					'date': {
						preset: 'date'
					},
					'select': {
						preset: 'select'
					}
				};
				$('.select').scroller('destroy').scroller($.extend(opt['select'], {
					theme: "ios7",
					mode: "scroller",
					display: "bottom",
					animate: ""
				}));
			});

			//绑定仓库
			function bindCk() {
				var userinfo = summer.getStorage("userinfo");
				doPost(adressHead.ISjtzImpl, "getBdDoc", {
					dataParm: {
						dostype: "nc_ck_" + userinfo.empId
					}
				}, function(jsons) {
					angularScope.cangku = jsons;
					angularScope.$apply();
					$("#selectcangku_dummy").val("请选择");
				}, null, true);
			}

			function RQ() {
				summer.openScanner({
					callback: function(args) {
						var code;
						try {
							code = args.umdcode.toString();
						} catch(e) {
							code = args;
						}

						var pp = "未知";
						switch(code[0].toUpperCase()) {
							case "P":
								pp = "普天";
								break;
							case "C":
								pp = "创品";
								break;
							case "D":
								pp = "迪讯";
								break;
							case "B":
								pp = "保千里";
								break;
							case "X":
								pp = "信颐";
								break;
							case "M":
								pp = "熊猫";
								break;
							case "Z":
								pp = "中车";
								break;
						}

						if(pp == "未知") {
							UM.toast({
								title: '友情提示：',
								text: '不能识别的品牌编号'
							});
							return;
						}
						for(var i = 0; i < angularScope.devices.length; i++) {
							if(angularScope.devices[i].deviceId == code) {
								UM.toast({
									title: '友情提示：',
									text: '当前设备已扫入，请更换'
								});
								return;
							}
						}

						if(!angularScope.devices) { angularScope.devices = []; }
						if(angularScope.devices.length != 0) {
							angularScope.devices.push({
								point: angularScope.devices[angularScope.devices.length - 1].point,
								deviceId: code, //设备号
								brand: pp //品牌
							});
						} else {
							angularScope.devices.push({
								point: { doc_name: "请选择" },
								deviceId: code, //设备号
								brand: pp //品牌
							});
						}

						angularScope.$apply();
					}
				});
			}

			$('.select').change(function() {
				$("#" + $(this).attr("id") + "_dummy").val($(this).find("option:selected").text());
			});

			function Submit() {
				/*var zc = angularScope.devices;
				var userinfo = summer.getStorage("userinfo");
				if(!zc) {
					UM.toast({
						title: '友情提示：',
						text: '请先扫描设备'
					});
					return;
				}
				if(zc.length == 0) {
					UM.toast({
						title: '友情提示：',
						text: '请先扫描设备'
					});
					return;
				}
				if(!angularScope.warehouseid) {
					UM.toast({
						title: '友情提示：',
						text: '请先选择仓库'
					});
					return;
				}
				//if(!checkNumber(angularScope.isNeedExtendevice)) {
				//		toasts("请填写正确的加长装置数量");
				//		return;
				//	}
				if(Number(angularScope.isNeedExtendevice) > Number(angularScope.jczz_num)) {
					toasts("加长装置数量不能超过" + angularScope.jczz_num);
					return;
				}

				//if(!checkNumber(angularScope.hoistingCount)) {
				//		toasts("请填写正确的设备吊装支架数量");
				//		return;
				//	}
				if(Number(angularScope.hoistingCount) > Number(angularScope.dzzj_num)) {
					toasts("吊装支架数量不能超过" + angularScope.dzzj_num);
					return;
				}

				var data = [];
				for(var i = 0; i < zc.length; i++) {
					if(!zc[i].point.pk_doc) {
						UM.toast({
							title: '友情提示：',
							text: '第' + (i + 1).toString() + "台设备未选择物料，请先选择"
						});
						return;
					}

					data.push({
						deviceId: zc[i].deviceId,
						materialoid: zc[i].point.pk_doc,
						brand: zc[i].brand,
						isNeedExtendevice: Number(angularScope.isNeedExtendevice),
						hoistingCount: Number(angularScope.hoistingCount),
					});
				}

				doPost(adressHead.ISjtzImpl, "saveRealHair_V2", {
					dataParm: {
						empId: userinfo.empId,
						billid: pageParam.billid,
						confirmDelivery: "Y",
						deliveryCount: zc.length,
						status: "2",
						warehouseid: angularScope.warehouseid,
						data: data
					}
				}, function(jsons) {
					if(jsons.result != 1) {
						toasts(jsons.msg);
						return;
					}
					toasts('提交成功');
					setTimeout(function() {
						summer.execScript({
							winId: 'ActualMain',
							script: "rebind()"
						});
						summer.closeWin();
					}, 1000);
				});*/
				toasts('提交成功');
			}

			var app = angular.module('myApp', []);
			app.controller('myCtrl', function($scope, $http) {
				angularScope = $scope;
				$scope.changePage = function(index) { //点击跳转选择点位 记录index
					$scope.changePageIndex = Number(index);
					$('#toActualport').click();
				}
				$scope.changePort = function(index) { //选中后跳转
					//判断选择的点位是否已经用了
					//					for(var i = 0; i < $scope.devices.length; i++) {
					//						if($scope.devices[i].point.pointid == $scope.pointData[Number(index)].pointid) {
					//							toasts("该点位已被选择，请选择其他点位");
					//							return;
					//						}
					//					}

					var codeName = $scope.pointData[Number(index)].doc_name;
					var codeCount; //当前选择设备的允许最大数量
					switch($scope.pointData[Number(index)].doc_name) {
						case "42寸立式三屏网络智能终端机":
							codeCount = Number(angularScope.sb01_num);
							break;
						case "43寸立式三屏网络智能终端机":
							codeCount = Number(angularScope.sb02_num);
							break;
						case "50寸立式三屏网络智能终端机":
							codeCount = Number(angularScope.sb03_num);
							break;
						case "49寸挂式单屏网络智能终端机":
							codeCount = Number(angularScope.sb04_num);
							break;
						case "43寸挂式单屏网络智能终端机":
							codeCount = Number(angularScope.sb05_num);
							break;
					}
					var thiscount = 0; //当前最大数量
					for(var i = 0; i < $scope.devices.length; i++) {
						if($scope.devices[i].point) {
							if($scope.devices[i].point.doc_name == codeName) {
								thiscount++;
							}
						}
					}
					if($scope.devices[$scope.changePageIndex].point.doc_name == codeName) {
						thiscount--;
					}
					if(thiscount >= codeCount) {
						UM.toast({
							title: '友情提示：',
							text: '当前设备已超过最大数，请重新选择'
						});
						return;
					}

					$scope.devices[$scope.changePageIndex].point = $scope.pointData[Number(index)];
					$scope.changePageIndex = null;
					$(".toActual").click();
				}

				$scope.deleteDriver = function(index) { //删除设备
					var asdsad = $scope.devices;
					asdsad.splice(index, 1);
					$scope.devices = asdsad;
					$scope.$apply();
				}
				$scope.isNeedExtendevice = 0;
				$scope.hoistingCount = 0;
			});
			summerready = function() {
				pageParam = summer.pageParam;
				//pageParam = {"DeliveryDate":"2017-03-22 18:43:58","billid":"1001A810000000013WSN","builderUnit":"洪晋安装公司","cs":"1001A81000000000ZR3O","dispatchDate":"2017-03-22 00:00:00","dispatchTime":"2017-03-22 13:14:34","dzzj_num":"0","engineeringSupervisor":"洪晋接单人","equipmentQuantity":"3","expressType":"Y","jczz_num":"-1","pointData":[],"remainingCount":"2","sb01_num":"1","sb02_num":"0","sb03_num":"0","sb04_num":"1","sb05_num":"1"};

				bindCk();
				angularScope.builderUnit = pageParam.builderUnit;
				angularScope.devices = [];
				angularScope.pointData = pageParam.pointData;
				angularScope.sb01_num = pageParam.sb01_num;
				angularScope.sb02_num = pageParam.sb02_num;
				angularScope.sb03_num = pageParam.sb03_num;
				angularScope.sb04_num = pageParam.sb04_num;
				angularScope.sb05_num = pageParam.sb05_num;
				angularScope.dzzj_num = pageParam.dzzj_num;
				angularScope.jczz_num = pageParam.jczz_num;
				angularScope.$apply();

				//选择物料
				doPost(adressHead.ISjtzImpl, "getBdDoc", {
					dataParm: {
						dostype: "app_wl"
					}
				}, function(jsons) {
					angularScope.pointData = jsons;
					angularScope.$apply();
				}, null, true);
			}
		</script>
	</body>

</html>
<script src="../../js/Myjs/Common.js"></script>